clear;clearvars;clc;
load('Iris.mat', 'iris');
A = iris;
%生成随机排列，以便划分成测试和训练数据
nrows = size(A, 1);
randrows = randperm(nrows);

X = A;
k = 5;
fold = 10;
for chunk = 1 : fold
    chunksize = floor(nrows/fold);
    x = (chunk - 1) * chunksize + 1;
    y = chunk * chunksize;
    testdata = X(randrows(x:y), :);
    if chunk == 1
        traindata = X(randrows(y + 1:end), :);
    elseif chunk == fold
        traindata = X(randrows(1 : x-1), :);
    else
        traindata = X(randrows(1, x-1:y+1, end), :);
    end
    currentacc = knnclassifier(traindata, testdata, k);
    s(chunk) = currentacc;
end
% 获得其均值
meanaccuracy = mean(s);
disp(meanaccuracy);

